import { defineStore } from 'pinia'
import { $get } from '@/lib/plugin/Aegis'

type RootState = {
  dayData: {
    visit_total: number;
    visitor_total: number

  } | null;
  historyData: {
    visit_total: number;
    visitor_total: number
  } | null;
};

export const logStore = defineStore('log', {
  state: () => {
    return {
      dayData: null,
      historyData: null
    } as RootState
  },
  getters: {},
  actions: {
    setDayData (res:any):void {
      this.dayData = res
    },
    setHistoryData (res:any):void {
      this.historyData = res
    },
    async getVisitorDayData (paylod:any) {
      try {
        this.dayData = await $get('visitor_log/day', {
          startTime: paylod.startTime,
          endTime: paylod.endTime
        })
      } catch (error) {
        console.log(error)
      }
    },
    async getVisitorHistoryData () {
      try {
        this.historyData = await $get('visitor_log/history')
      } catch (error) {
        console.log(error)
      }
    }
  }
})
